package com.team.teamproject.ui;

import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.view.Window;
import android.widget.RadioGroup;

import com.team.teamproject.R;
import com.team.teamproject.ui.classfiy.FragmentFenLei;
import com.team.teamproject.ui.homepage.FragmentFirstPage;
import com.team.teamproject.ui.hot.FragmentReMen;
import com.team.teamproject.ui.my.FragmentWode;

public class MainActivity extends AppCompatActivity {
   //主界面
   private RadioGroup mRg;
    private FragmentManager manager;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //去掉标题
        supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_main);
        //初始化控件
        mRg= (RadioGroup) findViewById(R.id.group_main);
        //动态填充Fragment
        addFragment();
    }

    private void addFragment() {
        manager=getSupportFragmentManager();
        FragmentTransaction transaction = manager.beginTransaction();
        //默认显示首页
        transaction.replace(R.id.frame_main,new FragmentFirstPage());
        transaction.commit();
        //redioGroup
        mRg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                FragmentTransaction transaction = manager.beginTransaction();
                switch (checkedId){
                    case R.id.rbtn_fistpage:  //首页
                        transaction.replace(R.id.frame_main,new FragmentFirstPage());
                        break;
                    case R.id.rbtn_bangdan://榜单
                        transaction.replace(R.id.frame_main,new FragmentReMen());
                        break;
                    case R.id.rbtn_fenlei://分类
                        transaction.replace(R.id.frame_main,new FragmentFenLei());
                        break;
                    case R.id.rbtn_wode://我的
                        transaction.replace(R.id.frame_main,new FragmentWode());
                        break;
                }
                transaction.commit();
            }
        });
    }
}
